﻿//--------------------------------------------------------------------------
//
//  File:        MoveStringConverter.cs
//
//  Coder:       bigeagle@gmail.com
//
//  Date:        2013/2/20
//
//  Description: 棋步到字符串的转换类，用于数据绑定
//  
//  History:     2013/2/20 created by bigeagle  
//
//--------------------------------------------------------------------------

using Bigeagle.Portable.BoardGames;
using Bigeagle.Portable.BoardGames.Go;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace EagleGO
{
    /// <summary>
    /// 棋步到字符串的转换类，用于数据绑定
    /// </summary>
    class MoveStringConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            StringBuilder builder = new StringBuilder();
            CommentsMove move = (CommentsMove)value;
            if (move != null)
            {
                if (move.IsRealMove)
                {
                    builder.Append(string.Format("第{0}手", move.Step).PadRight(6));
                    builder.Append(move.Name);
                    builder.Append(move.Side == Stone.Sides.Black ? "黑 [" : "白 [");
                    builder.Append((char)('a' + move.X));
                    builder.Append(19 - move.Y);
                    builder.Append("] ");
                    builder.Append(!string.IsNullOrEmpty(move.Comment) ? " [注释] " : " ");
                    if (move.ForceMoveNumber > 0)
                    {
                        builder.Append(" [重置] ");
                    }
                    if (move.Labels.Count > 0)
                    {
                        builder.Append(string.Format(" [标签{0}] ", move.Labels.Count));
                    }
                }
                else
                {
                    builder.Append("      ");
                    builder.Append(move.Name);
                    builder.Append(!string.IsNullOrEmpty(move.Comment) ? " [注释] " : " ");
                    if (move.ForceMoveNumber > 0)
                    {
                        builder.Append(" [重置] ");
                    }
                    if (move.Labels.Count > 0)
                    {
                        builder.Append(string.Format(" [标签{0}] ", move.Labels.Count));
                    }

                }

            }
            return builder.ToString().ToUpper().PadRight(40);
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }//end class

    /// <summary>
    /// 子棋局转换为是否显示属性
    /// </summary>
    class SubGamesVisibilityConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, string language)
        {
            List<GoGameBase> games = (List<GoGameBase>)value;
            if (games != null)
            {
                return games.Count > 0 ? Visibility.Visible : Visibility.Collapsed ;
            }

            return Visibility.Collapsed ;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }//end class
}//end namespace
